package at.jku.se.fastsell.db4o.transactions;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import at.jku.se.fastsell.data.Bid;
import at.jku.se.fastsell.db4o.DatabaseException;

public class StoreBidTransaction extends Transaction {
	
	private Bid b;
	
	StoreBidTransaction(Bid b) {
		this.b = b;
	}

	@Override
	public Object run() throws DatabaseException {
//		Key key = KeyFactory.createKey("Bid", "Fastsell");

		Entity userEntity = new Entity("Bid", key);
		userEntity.setProperty("price", b.getPrice());
		userEntity.setProperty("bidder", b.getBidder().getName());
		
//		DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		datastore.put(userEntity);
		return null;
	}

}
